<?php 
    session_start();
    echo "Login: ".$_SESSION["userID"]." ".$_SESSION["userType"];
?>

<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
                
        <link rel="stylesheet" href="styles/layout.css" type="text/css"/>
        <link rel="stylesheet" href="styles/computer.css" type="text/css"/>
        <script type="text/javascript" src="scripts/computer.js"></script>
    </head>
    <?php
    require 'header.html';
    ?>
<div id="container">
  <div class="wrapper">
    <div id="content">
    	<div id="order">    
    <body>
        <?php
        // put your code here
        
        if(isset($_SESSION["userID"]) && !strcmp($_SESSION["userType"], "seller")){

        $saleID = $_POST["saleID"];
            if(strlen($saleID) == 0){
                //add a new product
                echo "<h2>Add a new sale</h2>";
            }else{
                echo "<h2>Change selected sale</h2>";
                $con = mysql_connect("localhost", "zhouzhao", "19831022");
                if(!$con){
                    die("could not connect to DB: ".mysql_error());
                }
                
                mysql_select_db("cloudcom", $con);
                $result = mysql_query("select * from sales where saleID = $saleID");
                $row = mysql_fetch_assoc($result);
                
                mysql_close($con);
            }
        ?>
        
        
        <form method="post" action="commitSale.php">
            <input type="text" name="saleID" style="display: none"
                   <?php
                   if(strlen($saleID) != 0){
                       echo "value='".$saleID."'";
                   }
                   ?>
                   />
            <p>Product ID: <input type="text" name="productID" maxlength="20" class="rightAlign"
                         <?php
                         if(strlen($saleID) != 0){
                             echo "value='".$row["productID"]."'";
                         }
                         ?>
                         /></p>
            <p>Discount: <input type="text" name="discount" maxlength="20" class="rightAlign"
                         <?php
                         if(strlen($saleID) != 0){
                             echo "value='".$row["discount"]."'";
                         }
                         ?>
                         /></p>
            <p>Start date: <input type="text" name="startDate" maxlength="20" class="rightAlign"
                         <?php
                         if(strlen($saleID) != 0){
                             echo "value='".$row["startDate"]."'";
                         }
                         ?>
                         /></p>
            <p>End date: <input type="text" name="endDate" maxlength="20" class="rightAlign"
                         <?php
                         if(strlen($saleID) != 0){
                             echo "value='".$row["endDate"]."'";
                         }
                         ?>
                         /><p>
                <input type="submit" name="button" value="Commit sale" class="buttonStyle" onmouseover="changeOn(this)" onmouseout="changeOff(this)"/>
                <input type="submit" name="button" value="Cancel" class="buttonStyle" onmouseover="changeOn(this)" onmouseout="changeOff(this)"/>
        </form>
        
        <?php
        }else{
            require 'login.html';
        }
        ?>
       </div>	
    </div>
    <br class="clear" />
  </div>
</div>
    <?php
        require 'tail.html';
    ?>
    </body>
</html>
